<template>
	<view>

		<mc-framework navTitle="MES工控机" @changeLevel="changeLevel">
			<template #content>
				<view class="content_box f-dc">
					<view class="table table_top_th">
						<table>
							<tr>
								<th width='20%'>维修单号</th>
								<th width='20%'>维修设备</th>
								<th width='10%'>申请人</th>
								<th width='30%'>故障描述</th>
								<th width='10%'>维修人</th>
								<th width='10%'>维修状态</th>
							</tr>
						</table>
					</view>
					<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" class="z_paging">


						<view class="table">
							<table class="table-full">

								<tbody>

									<tr style="border: 1px solid #ccc;" v-for="(item,index) in dataList" :key="index"
										@click="itemClick(item,index)" :class="{ hovered: hoveredIndex === index }">
										<td width='20%'>
											<div class="ListTdDiv"><text>{{item.BillNO}}</text></div>
										</td>
										<td width='20%'>
											<div class="ListTdDiv"><text>{{item.EquipmentName}}</text></div>
										</td>
										<td width='10%'>
											<div class="ListTdDiv"><text>{{item.ApplyForMan}}</text></div>
										</td>
										<td width='30%'>
											<div class="ListTdDiv"><text>{{item.BXContent}}</text></div>
										</td>
										<td width='10%'>
											<div class="ListTdDiv"><text>{{item.MaintainMan}}</text></div>
										</td>

										<td width='10%'>
											<div class="ListTdDiv"><text>{{item.WCStatus?'已维修':'未维修'}}</text></div>
										</td>

									</tr>
								</tbody>
							</table>
						</view>
					</z-paging>
				</view>
				<view class="add">
					<u-icon name="plus" color="#fff" size="30" @click="add"></u-icon>
				</view>
				<view class="search">
					<u-icon name="search" color="#fff" size="30" @click="search"></u-icon>
				</view>

				<uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0"
					@change="changePopup">
					<view class="popup_content">
						<u-cell-group :border='false'>
							<u-cell title="设备名称" :isLink="false" :value='FormData.EquipmentName'
								@click="openBaseScreen('机台')"></u-cell>
							<u-cell title="保养状态" :isLink="false" :value="getBYStatus( FormData.WCStatus)"
								@click="addBYStatus()"></u-cell>
							<u-cell title="开始时间" :isLink="false" :value='FormData.FBDate'
								@click="addTime('开始')"></u-cell>
							<u-cell title="结束时间" :isLink="false" :value='FormData.FEDate'
								@click="addTime('结束')"></u-cell>
						</u-cell-group>
						<view class="bottomBtns">
							<button block @click="submit">
								查 &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 询
							</button>
						</view>

					</view>
				</uni-popup>

				<u-datetime-picker :show="show" v-model="value1" mode="date" @cancel='show = false'
					@confirm='pickerConfirm'></u-datetime-picker>

				<u-action-sheet :actions="BYStatusList" :show="BYStatusShow" @select="BYStatusClick"
					@close="BYStatusShow=false"></u-action-sheet>

			</template>

		</mc-framework>

	</view>
</template>

<script>
	import {
		getTimeStamp,
		getFormatDateTime,
		getBefore7DateTime
	} from '@/mes/common/base.js';
	export default {
		data() {
			return {
				disabled:false,
				dataList: [],
				APPFunID: 0,
				tabIndex: 0,
				showLeft: false,
				FormData: {
					EquipmentID: 0,
					EquipmentName: '全部',
					PageIndex: 1,
					PageSize: 30,
					FBDate: '',
					FEDate: '',
					WCStatus: -1
				},
				TimeName: '',
				show: false,
				value1: Number(new Date()),
				hoveredIndex: null,

				BYStatusShow: false,
				BYStatusList: [{
						name: '全部',
						id: -1
					}, {
						name: '未维修',
						id: 0
					},
					{
						name: '已维修',
						id: 1
					}
				],
			}

		},
		onLoad() {
			this.FormData.FBDate = getBefore7DateTime()
			this.FormData.FEDate = getFormatDateTime(new Date())
			this.FormData.EquipmentName = this.$store.state.GuyueModule.MesBasicInfo.warehouse.EquipmentName
			this.FormData.EquipmentID = this.$store.state.GuyueModule.MesBasicInfo.warehouse.EquipmentID
			this.$store.state.GuyueModule.MesBasicInfo.Status.ClockStatusTitle = '其他'

		},
		onShow() {
			this.getValue
			this.getList
		},
		methods: {
			getList() {
				this.contents = []; // 假设这是异步获取数据的操作
				this.$refs.paging.reload();
			},
			getBYStatus(value) {
				switch (value) {
					case -1:
						return '全部';
					case 0:
						return '未维修';
					default:
						return '已维修';
				}
			},
			BYStatusClick(e) {
				this.FormData.WCStatus = e.id
				this.BYStatusShow = false
			},
			addBYStatus() {
				this.BYStatusShow = true
			},

			getValue(e) {
				console.log(e);
				if (e != '返回') {
					this.FormData.EquipmentID = e.EquipmentID
					this.FormData.EquipmentName = e.name
					this.$forceUpdate()
				}

			},

			openBaseScreen(str) {
				var that = this;
				var obj;
				if (str == '机台') {
					obj = {

						type: str,
						cmd: 'getEquipment',
						param: {
							FWorkshopID: '1009'
						}
					}
				}
				uni.navigateTo({
					url: `../common/baseScreen?obj=${JSON.stringify(obj)}`,
					animationType: 'slide-in-right',
					animationDuration: 300
				});
			},

			addTime(name) {
				this.TimeName = name
				if (this.TimeName == '开始') {
					this.value1 = Number(getTimeStamp(this.FormData.FBDate))
				} else {
					this.value1 = Number(getTimeStamp(this.FormData.FEDate))
				}
				this.show = true
			},

			pickerConfirm(e) {
				var time = getFormatDateTime(e.value)
				if (this.TimeName == '开始') {
					this.FormData.FBDate = time
				} else {
					this.FormData.FEDate = time
				}
				this.show = false
			},
			changePopup() {

			},
			search() {
				this.$refs.popup.open('bottom')

			},
			submit() {
				this.$refs.popup.close('bottom')
				this.contents = []; // 假设这是异步获取数据的操作
				this.$refs.paging.reload();
			},
			add() {
				let routes = getCurrentPages();
				let obj = {
					length: routes.length + 1,
					Name: '设备维修详情',
					APPFunID: '设备维修详情'
				}
				var url = './devicerepairDetail'
				this.GonavigateTo(obj, url)
			},

			queryList(pageNo) {
				let that = this;

				that.FormData.PageIndex = pageNo
				that.Request.request('getMaintainEquipmentList', this.FormData, function(ret) {
					// console.log(ret)
					if (ret.status == 200) {
						that.$refs.paging.complete(ret.data.ds);
					}
				})
			},
			itemClick(item, index) {
				let routes = getCurrentPages();
				let obj = {
					length: routes.length + 1,
					Name: '设备维修详情',
					APPFunID: '设备维修详情'
				}
				var url = `./devicerepairDetail?MaintainEquipmentID=${item.MaintainEquipmentID}`
				this.GonavigateTo(obj, url)
			},

			GonavigateTo(obj, url) {
				let that = this;
				if (that.disabled == false) {
					// 立即禁用点击
					that.disabled = true
					let newData = JSON.parse(JSON.stringify(this.$store.state.GuyueModule.ModuleData_select));
					newData.push(obj);
					this.$store.commit('GuyueModule/ChangeAndSetStateData', {
						Name1: 'ModuleData_select',
						data: newData
					})
					uni.navigateTo({
						url: url,
						animationType: 'slide-in-right', // 动画类型
						animationDuration: 300 // 动画时长
					});
					setTimeout(() => {
						that.disabled = false
					}, 4000)
				}
			},
			changeLevel(data, row) {
				let routes = getCurrentPages(); //当前页面栈
				let backIndex = routes.length - row.length; // 计算返回页面栈数

				uni.navigateBack({
					delta: backIndex
				})

			},
		},


		onNavigationBarButtonTap(e) {
			if (this.showLeft) {
				this.$refs.showLeft.close()
			} else {
				this.$refs.showLeft.open()
			}
		},
		// app端拦截返回事件 ，仅app端生效
		onBackPress() {
			if (this.showRight || this.showLeft) {
				this.$refs.showLeft.close()
				this.$refs.showRight.close()
				return true
			}
		}
	}
</script>

<style lang="scss">
	@import "../css/index.css";
</style>